package com.fastloan.jn.mgt.customer.controller;

import com.fastloan.jn.mgt.customer.model.JnCustomerContact;
import com.fastloan.jn.mgt.customer.service.JnCustomerContactService;
import com.kawins.base.baseabs.BaseController;
import com.kawins.result.ResultEnum;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenkai
 *         createTime 2017-10-2017/10/17 15:50
 */
@RestController
@RequestMapping("/api/web/customer/contact")
public class JnCustomerContactController extends BaseController<JnCustomerContact> {
    @Autowired
    private JnCustomerContactService contactsService;

    /**
     * 联系人列表
     *
     * @param customerId
     * @return
     */
    @RequestMapping("/{customerId}/pageList")
    public ResultTo pageList(@PathVariable String customerId) {
        Map<String, Object> map = new HashMap<>(1);
        map.put("customerId", customerId);
        return dataPage(map);
    }

    /**
     * 获取联系人信息
     *
     * @param bankId
     * @return
     */
    @GetMapping("/{bankId}")
    public ResultTo getBank(@PathVariable String bankId) {
        return new ResultTo().setData(contactsService.selectByPrimaryKey(bankId));
    }

    /**
     * 新增联系人信息
     * @param customerContacts
     * @return
     */
    @PostMapping
    public ResultTo add(JnCustomerContact customerContacts) {
        return contactsService.insertSelective(customerContacts) != 0 ? new ResultTo() : new ResultTo(ResultEnum.OPERATION_FAILED);
    }

    /**
     * 更新联系人信息
     * @param customerContacts
     * @return
     */
    @PutMapping
    public ResultTo update(JnCustomerContact customerContacts) {
        return contactsService.updateByPrimaryKeySelective(customerContacts) != 0 ? new ResultTo() : new ResultTo(ResultEnum.OPERATION_FAILED);
    }
}
